<template>
  <div class="app-container">

    <section :style="style" v-show="visible" class="infoBoxList">
      <el-form>
        <el-form-item label="勤务部数据列表">
        </el-form-item>
      </el-form>
      <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="名称" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="类型" prop="type">
          <el-select v-model="queryParams.type" placeholder="请选择类型" clearable size="small">
            <el-option
              v-for="dict in typeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        </el-form-item>
      </el-form>


      <el-table v-loading="loading" :data="deploymentList">
        <el-table-column label="主建id" align="center" prop="id" v-if="false"/>
        <el-table-column label="名称" align="center" prop="name"/>
        <el-table-column label="类型" align="center" prop="type" :formatter="typeFormat"/>
        <el-table-column label="责任管理区" align="center" prop="area"/>
        <el-table-column label="第一责任人姓名" align="center" prop="firstName"/>
        <el-table-column label="第一责任人联系方式" align="center" prop="firstContact"/>
        <el-table-column label="具体责任人姓名" align="center" prop="specificName"/>
        <el-table-column label="具体责任人联系方式" align="center" prop="specificContact"/>
        <el-table-column label="船管站" align="center" prop="shipOffice"/>
        <el-table-column label="工作站" align="center" prop="workStation"/>
        <el-table-column label="巡护人员" align="center" prop="patrolName"/>
        <el-table-column label="定位" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-location-information"
              @click="showPoint(scope.row)"
            >定位
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </section>
  </div>
</template>


<script>
  import { listDeployment } from '@/api/basicInformation/deployment'

  export default {
    name: 'deploymentlist',
    components: {},
    props: {
      visible: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        style: null,
        style2: null,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 勤务部署基本信息表格数据
        deploymentList: [],
        // 类型字典
        typeOptions: [],
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: undefined,
          type: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          type: [
            { required: true, message: '类型不能为空', trigger: 'change' }
          ]
        }
      }
    },
    created() {
      this.getList()
      this.getDicts('service_deployment_type').then(response => {
        this.typeOptions = response.data
      })
    },
    methods: {
      /** 查询巡护任务列表 */
      getList() {
        this.loading = true
        listDeployment(this.queryParams).then(response => {
          this.deploymentList = response.rows
          this.total = response.total
          this.loading = false
        })
      },
      // 类型字典翻译
      typeFormat(row, column) {
        return this.selectDictLabel(this.typeOptions, row.type)
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1
        this.getList()
      },
      showPoint(row) {
        row.typeName = this.selectDictLabel(this.typeOptions, row.type)
        this.$emit('showPoint', row)
      }
    }
  }
</script>
<style scoped lang="scss">
  .el-form-item {
    margin-bottom: 10px;
  }
</style>
